package com.qyhl.module_practice.score.mine.shopping;


import com.qyhl.module_practice.common.PracticeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeScoreMyShoppingBean;

import java.util.List;

public class PracticeScoreMyShoppingModel implements PracticeScoreMyShoppingContract.PracticeScoreMyShoppingModel {
    private PracticeScoreMyShoppingPresenter mPresenter;

    PracticeScoreMyShoppingModel(PracticeScoreMyShoppingPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getList(String volId, final String page) {
        EasyHttp.get(PracticeUrl.GET_PRACTICE_MY_SHOPPING_LIST)
                .params("volId", volId)
                .params("page", page)
                .execute(new SimpleCallBack<List<PracticeScoreMyShoppingBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无更多内容", !page.equals("1"));
                        } else {
                            mPresenter.setError("获取失败，请稍后再试！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<PracticeScoreMyShoppingBean> practiceScoreMyShoppingBeans) {
                        if (practiceScoreMyShoppingBeans != null && practiceScoreMyShoppingBeans.size() > 0) {
                            mPresenter.setList(practiceScoreMyShoppingBeans, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无更多内容", !page.equals("1"));
                        }
                    }
                });

    }
}
